<?php if(isset($data)){ ?>
    <?php
    $form = $this->beginWidget('CActiveForm', array(
        'id' => 'news-form',
        'enableAjaxValidation' => true,
        'enableClientValidation' => true,
        'htmlOptions' => array(
            'class' => 'form-horizontal',
        ),
    ));
    ?>
    <div class="customer-info">
        <h4>Thông Tin Khách Hàng</h4>
        <div class="control-group">
            <label class="control-label">Họ</label>
            <div class="controls">
                <input name="Customer[first_name]" type="text" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Tên</label>
            <div class="controls">
                <input name="Customer[last_name]" type="text" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Email</label>
            <div class="controls">
                <input name="Customer[email]" type="text" />
                <input name="OrganizerOrder[event_id]" type="hidden" value="<?php echo $data->id; ?>" />
            </div>
        </div>
        <div class="control-group">
            <label class="control-label">Phone</label>
            <div class="controls">
                <input name="Customer[phone]" type="text" />
            </div>
        </div>
    </div>
<div class="tabbable">
    <ul id="myTab" class="nav nav-tabs ticket-tabs">
        <?php foreach($data->tickets as $key => $tickets) : ?>
            <?php
            $result = MyFunctionCustom::remain_quantity(null, $tickets['temp_quantity'], $tickets['remain_quantity']);
            if ($result > 0) {
                $result = true;
            } else $result = false;
            ?>
            <?php if ($result == true) { ?>
                <li>
                    <a href="#tab_<?php echo $key; ?>" data-toggle="tab">
                        <b class="blue">
                            <?php echo $tickets->description_of_ticket; ?>
                        </b>
                    </a>
                </li>
            <?php } ?>
        <?php endforeach;?>
    </ul>
    <div class="tab-content">
        <?php foreach($data->tickets as $key => $tickets) : ?>
            <?php
            $result = MyFunctionCustom::remain_quantity(null, $tickets['temp_quantity'], $tickets['remain_quantity']);
            if ($result > 0) {
                $result = true;
            } else $result = false;
            ?>
        <?php if ($result == true) { ?>
            <div class="tab-pane "  id="tab_<?php echo $key; ?>">
                <dl id="dt-list-1" class="dl-horizontal">
                    <dt>Mã Vé</dt>
                    <dd><b class="blue"><?php echo $tickets->ticket_code; ?></b></dd>
                    <dt>Loại vé</dt>
                    <dd><b class="blue"><?php echo $tickets->description_of_ticket; ?></b></dd>
                    <dt>Giá</dt>
                    <dd><b class="red"><?php echo number_format($tickets->price); ?> VND / 1 Vé</b></dd>
                    <dt>Số lượng còn lại</dt>
                    <dd>
                        <?php $real_quantity = MyFunctionCustom::remain_quantity(null,$tickets->temp_quantity,$tickets->remain_quantity); ?>
                        <?php if ($real_quantity < 20) : ?>
                            <b class="red">
                                <?php echo $real_quantity;  ?>
                            </b>
                        <?php else : ?>
                            <b class="blue"><?php echo $real_quantity; ?></b>
                        <?php endif; ?>
                    </dd>
                </dl>
                <div class="control-group">
                    <label class="control-label">Số lượng vé</label>
                    <div class="controls">
                        <select class="price_details span2" name="DirectBook[<?php echo $key; ?>][quantity]">
                            <?php for($i = 0; $i <= 10; $i++) : ?>
                                <?php if($i == 0) : ?>
                                    <option selected="selected" value="<?php echo $i;  ?>"> <?php echo $i;  ?></option>
                                <?php else : ?>
                                    <option value="<?php echo $i;  ?>"> <?php echo $i;  ?></option>
                                <?php endif;?>
                            <?php endfor; ?>
                        </select>
                        <input name="DirectBook[<?php echo $key; ?>][ticket_id]" type="hidden" value="<?php echo $tickets->id; ?>" />
                        <input name="DirectBook[<?php echo $key; ?>][price]" type="hidden" value="<?php echo $tickets->price; ?>" />
                        <input name="DirectBook[<?php echo $key; ?>][ticket_code]" type="hidden" value="<?php echo $tickets->ticket_code; ?>" />
                    </div>
                </div>
                <div class="control-group">
                    <div class="controls">
                        <b class="red">Mỗi vị trí chỗ ngồi cách nhau bằng dấu phẩy(,)</b>
                    </div>
                </div>
                <div class="control-group">
                    <label class="control-label">Chỗ ngồi</label>
                    <div class="controls">
                        <input name="Organizer[<?php echo $key; ?>][seat]" type="text" />
                    </div>
                </div>
                <div class="form-action">
                    <button class="btn btn-info organizer-book" type="submit">
                        <i class="icon-ok bigger-110"></i>
                        Xác nhận
                    </button>
                    &nbsp; &nbsp; &nbsp;
                    <button class="btn" type="reset">
                        <i class="icon-undo bigger-110"></i>
                        Làm lại
                    </button>
                </div>


            </div>
        <?php }?>
        <?php endforeach;?>
    </div>
</div>
    <?php $this->endWidget() ?>
<script type="text/javascript">
    $(document).ready(function(){
        $(".ticket-tabs li").first().addClass("active");
        $(".tab-content .tab-pane").first().addClass("active");
    });
    $('.organizer-book').on('click',function(e){
        $('.event-form').empty();
        $('.event-form').append('<div class="loading"><div style="width:134px;height:100px;margin:0 auto;padding-top: 10px;"><img src="<?php echo Yii::app()->theme->baseUrl; ?>/frontend/images/ajaxloader.gif"></div></div>');
        $request.ajaxSubmit($(this), function(html) {

            $('.event-form').html(html);
        });
        return false;
    });
</script>
<?php } else { ?>
     <h1>Không có sự kiện nào.</h1>
<?php } ?>